package com.studentManagement.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2017/4/27 0027.
 */
public class CookieUtil {
    //得到cookie中name的值
    public static String getCookieValueByName(Cookie cookies[], String name) {
        String value = null;
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                if (name.equals(cookies[i].getName())) {
                    value = cookies[i].getValue();
                }
            }
        }
        return value;
    }
    //用户名密码保存在cookie中
    public static void saveUsernameAndpassword_day(HttpServletResponse response,String username, String password , int day){
        Cookie usernameCookie = new Cookie("autoUsername", username);
        Cookie passwordCookie = new Cookie("autoPassword", password);
        usernameCookie.setMaxAge(day * 24 * 60 * 60);
        passwordCookie.setMaxAge(day * 24 * 60 * 60);
        response.addCookie(usernameCookie);
        response.addCookie(passwordCookie);
    }
}
